﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using Ths.Framework;
using Ths.Components.Common;
using Ths.Components.Dictionary;
using Ths.Components.Dictionary.Entity;
//using TestLuoQingHua.Data.CommonData;
using SafetyRecordData.Data.DAL;
using System.Data.OleDb;
using qiupeng.Public;
public partial class DistressManage_Hurt_update : Base
{
    #region 属性
    /// <summary>
    /// 主键值，同时适用于工作流
    /// </summary>
    public string AppId
    {
        get
        {
            string appId = GetRequestStr("appid");
            if (appId == string.Empty)
            {
                appId = txtAppID.Text;
            }

            return appId;
        }

    }

    /// <summary>
    /// 是否是添加
    /// </summary>
    public bool IsNew
    {
        get
        {
            if (ViewState["IsNew"] != null)
                return Convert.ToBoolean(ViewState["IsNew"]);
            else
                return GetRequestStr("isnew") != string.Empty;
        }

        set
        {
            ViewState["IsNew"] = value;
        }

    }

    /// <summary>
    /// 是否是浏览
    /// </summary>
    public bool IsView
    {
        get
        {
            return GetRequestStr("view") != string.Empty;
        }

    }

    #endregion
    Db List = new Db();
    DAHurtDistress dal = new DAHurtDistress();
    public string XinagPian = "nothing.jpg";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.BindList();

            if (!this.IsNew && this.AppId != string.Empty)
            {
                dal.SetValue(this.Controls, this.AppId);

                string SQL_GetList = "select * from qp_hr_Staff where gonghao='" + List.GetFormatStr(this.txtWorkernumber.Text) + "'";
                OleDbDataReader NewReader = List.GetList(SQL_GetList);
                if (NewReader.Read())
                {
                    
                    XinagPian = NewReader["XiangPian"].ToString();
                   
                }
                NewReader.Close();

            }

            else
            {
                txtAppID.Text = System.Guid.NewGuid().ToString();
            }

            if (Request.Params["view"] != null)
            {
                ClientScript.RegisterStartupScript(typeof(Page), "a", "<script>ChangeToLabel();</script>");
                this.btnPrint.Visible = true;
                this.img_danwei.Style.Add("display","none");
                this.imgSearch2.Style.Add("display", "none");
                
            }
        }
    }

    private void BindList()
    {
        BindDropDownList(drpType, "name", "id", dal.GetBasicData("2"), true);
        BindDropDownList(drpCategory, "name", "id", dal.GetBasicData("38"), true);
        BindDropDownList(drpHurtbody, "name", "id", dal.GetBasicData("7"), true);
        BindDropDownList(drpLeval, "name", "id", dal.GetBasicData("10"), true);
        BindDropDownList(drpEducationnal, "name", "id", dal.GetBasicData("1"), true);
        BindDropDownList(drpWorktype, "name", "id", dal.GetBasicData("47"), true);
    }

    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("HurtList.aspx?islook=" + GetRequestStr("islook") + "");
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            int i = 0;
            if (!this.IsNew)
            {
                i = dal.EditData(this.Controls, this.AppId);
            }

            else
            {
                if (dal.IsExists(this.AppId))
                {
                    i = dal.EditData(this.Controls, this.AppId);
                }
                else
                {
                    i = dal.AddData(this.Controls);
                    if (i > 0) IsNew = false;
                }

            }

            if (i <= 0)
            {
                Alert("操作失败，请检查。", this);
            }

            else
            {
                Alert("保存成功!", "", "window.location.href('HurtList.aspx')", false, this);
            }

        }

        catch (Exception ex)
        {
            Alert("操作失败，错误信息为：" + ex.Message.Replace("'", "''"), this);
        }

    }
}
